package com.jd.service;

import com.jd.dao.UserDAO;
import com.jd.po.User;



public class UserServiceImpl implements UserService {
	private UserDAO userDAO;
	@Override
	public boolean registerUser(User user) {
		//判断用户是否存在
		User queryUser = userDAO.queryByName(user.getUsername());
		if(queryUser == null) {
			return false;
		}else {
			userDAO.add(user);
			return true;
		}
	}

	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}
	@Override
	public User loginUser(User user) {
		//判断用户是否存在
		User queryUser = userDAO.queryByName(user.getUsername());
		if(queryUser == null) {
			return null;
		} else {
			if(queryUser.getPassword().equals(user.getPassword())) {
				return queryUser;
			} else {
				return null;
			}
		}
	} 
	@Override
	public String getGroups(User user) {
		User queryUser = userDAO.queryByName(user.getUsername());
		String groups = queryUser.getUserGroup();
		return groups;
	}


}
